﻿// -----------------------------------------------------------------------
// <copyright file="TileModel.cs" company="R&R">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

#region Imports
using System;
#endregion Imports

namespace Domino
{
    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class TileModel : BaseViewModel, IEquatable<TileModel>
    {
        #region Properties
        private int rightTileValue = -1;
        public int RightTileValue
        {
            get { return rightTileValue; }
            set { rightTileValue = value; RaisePropertyChanged("RightTileValue"); }
        }

        private int leftTileValue = -1;
        public int LeftTileValue
        {
            get { return leftTileValue; }
            set { leftTileValue = value; RaisePropertyChanged("LeftTileValue"); }
        }

        public int TileTotalValue { get { return LeftTileValue + RightTileValue; } }

        public bool IsPair { get; set; }

        private eTileLocation tileLocation;
        public eTileLocation TileLocation
        {
            get { return tileLocation; }
            set
            {
                tileLocation = value;
                if (tileLocation == eTileLocation.Board) IsPlayable = true;
            }
        }

        public string TileTooltip
        {
            get { return this.ToString(); }
        }

        private bool isNullValue;
        public bool IsNullValue
        {
            get { return isNullValue; }
            set { isNullValue = value; RaisePropertyChanged("IsNullValue"); }
        }

        private eTileOrientation tileOrientation;
        public eTileOrientation TileOrientation
        {
            get { return tileOrientation; }
            set { tileOrientation = value; RaisePropertyChanged("TileOrientation"); }
        }

        private bool isPlayable;
        public bool IsPlayable
        {
            get { return isPlayable; }
            set { isPlayable = (TileLocation == eTileLocation.Board ? true : value); RaisePropertyChanged("IsPlayable"); }
        }

        private bool allowHint;
        public bool AllowHint
        {
            get { return allowHint; }
            set { allowHint = value; RaisePropertyChanged("AllowHint"); }
        }
        #endregion Properties

        #region Constructors
        public TileModel(int leftTileValue, int rightTileValue)
        {
            // TODO: Complete member initialization
            if (leftTileValue < 0 || rightTileValue < 0)
                IsNullValue = true;
            else if (rightTileValue > leftTileValue)
            {
                this.RightTileValue = rightTileValue;
                this.LeftTileValue = leftTileValue;
            }
            else
            {
                this.RightTileValue = leftTileValue;
                this.LeftTileValue = rightTileValue;
            }

            IsPair = (RightTileValue == LeftTileValue);
        }
        #endregion Constructors

        #region Methods
        public bool Equals(TileModel other)
        {
            return this.ToString() == other.ToString();
        }

        public override string ToString()
        {
            return String.Format("{0},{1}", this.LeftTileValue, this.RightTileValue);
        }
        #endregion Methods
    }
}
